<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <style>
        .radio-inline input[type=radio] {
            margin-top: 4px;
        }
    </style>
</head>

<body style="color:#333;padding:3px;">
<!-- 标题 -->
<div>
    <form action="" class="form-inline">
        <table class="row-margin-top tab-content table-bordered table bud_hei" border="1">
            <tr>
                <td style="min-width: 140px;width: 140px"><label for="" class="form-label">核销单明细编号<span
                        class="colorRed">*</span>：</label></td>
                <td>
                    <div style="width:180px;float:left;">
                        <div class="input-group" id="hxdmxbh_input" style="display: none;">
                            <input type="text" class="form-control" id="hxdmxbh" placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                        <div id="hxdmxbh_queding" class="selectedOnlyOne">
                            <input type="hidden" name="hxdmxbh" value="{$data.hxdmxbh}">
                            <span class="inin">{$data.hxdmxbh_sn}</span>
                            <span class="close">×</span>
                        </div>
                    </div>
                    <a href="javascript:;" style="float:left;" id="selecthxdmxbh">选择</a>
                </td>
            </tr>
            <tr>
                <td><label for="" class="form-label">需补费的核销金额(元)：</label></td>
                <td>
                    <input type="hidden" name="hxje" value="{$data.hxje}">
                    <span id="hxje">{$data.hxje}</span>
                </td>
            </tr>
            <tr>
                <td><label for="" class="form-label">销售订单可补费金额(元)：</label></td>
                <td class="ObjectNum">
                    <input type="hidden" name="kbje" value="{$kbje}">
                    <span id="kbje">{$kbje}</span>
                </td>
            </tr>
            <tr>
                <td>本次补费金额(元) <span class="colorRed">*</span>:</td>
                <td><input type="text" class="form-control" name="bfje" value="{$data.bfje}"></td>
            </tr>
            <tr>
                <td colspan="2">备注：销售订单如限制货补、搭赠、补费的百分比，则销售订单可补费金额遵循该限制。</td>
            </tr>
        </table>
        <table class="table-bordered table bud_hei">
            <tr>
                <td style="width: 160px;">销售人员<span class="colorRed">*</span>:</td>
                <td>
                    <div style="width:178px;float:left;">
                        <div class="input-group" id="xsry_input" style="display: none;">
                            <input type="text" class="form-control" id="xsry" placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                        <div id="xsry_queding" class="selectedOnlyOne">
                            <input type="hidden" name="xsry" value="{$data.xsry}">
                            <span class="inin">{$data.xsry_name}</span>
                            <span class="close">×</span>
                        </div>
                    </div>
                    <a href="javascript:;" style="float:left;line-height:30px;" id="selectxsry">选择</a>
                </td>
            </tr>
            <tr>
                <td>销售部门：</td>
                <td><input type="hidden" name="ssbm" value="{$data.ssbm}"><span id="ssbm">{$data.ssbm_name}</span></td>
            </tr>
            <tr>
                <td>备注：</td>
                <td><textarea name="beizhu" id="" class="form-control"
                              style="user-select:none;height: 40px;width: 50%">{$data.beizhu}</textarea><span
                        style="vertical-align: bottom;">50</span></td>
            </tr>
        </table>
        <div class="row sub_btn" style="width:100%;text-align:center;padding: 20px 0">
            <input type="button" class="btn btn-info save" id="save2" value="保存">
            <input type="button" class="btn btn-warning" value="返回" id="fanhui">
        </div>
    </form>
</div>
<!-- 全局js -->
{include file="Public/footer"}
<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script>
    var hexiao = []
    var xsryName = []
    //保存
    $('.save').on('click',function () {
        var form = $(this).closest('form')
        var type = $(this).prop('id')
        $.post('',form.serialize()+'&order_id='+parent.$('#id').val(),function (data) {
            if(data.success){
                swal({title:data.msg},function () {
                    parent.location.reload()
                })
            }else{
                swal(data.msg,'','error')
            }
        },'json')
    })
    $('[name=bfje]').on('input',function () {
        var hxje = parseFloat($('[name=hxje]').val())
        var kbje = parseFloat($('[name=kbje]').val())

    })
    $('#fanhui').on('click',function () {
        parent.location.reload();
//        parent.layer.close(parent.layer.getFrameIndex(window.name))
    })
    //选择销售人员
    $('#selectxsry').on('click',function(){
        top.layer.open({
            type: 2,
            title: '&nbsp;',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px', '500px'],
            content: '{:url("open/employee2")}',
            btn:['确定','关闭'],
            yes:function (i,o) {
                var a = $(o).find('iframe').contents()

                var id =  a.find("#renyuan").val();
                var name =  a.find("#renyuanname").val();
                var ssbm_id = a.find('#ssbm_id').val();
                var ssbm = a.find('#ssbm').val();
                if(id){
                    var jxs_queding = $('#xsry_queding')
                    var jxs_input = $('#xsry_input')

                    jxs_queding.find('.inin').html(name)
                    jxs_queding.find('.inin').data('id',id)
                    jxs_queding.show()
                    jxs_queding.find('input').val(id)
                    jxs_input.hide()
                    $('[name=ssbm]').val(ssbm_id)
                    $('#ssbm').html(ssbm)
                }

                top.layer.close(i)
            }
        })
        return false
    })

    $("#xsry").bsSuggest({
        url: '{:url("bs/xsry",["jxs_id"=>request()->get("jxs_id")])}',
        effectiveFields: ["id", "em_name"],
        searchFields: [ "em_name"],
        effectiveFieldsAlias: {em_name: "姓名"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "em_name",
        clearable: true
    }).on('onDataRequestSuccess', function (e, result) {
        xsryName = result.value
        console.log('onDataRequestSuccess: ', result);
    }).on('onSetSelectValue', function (e, keyword) {
        $('#xsry_queding').find('.inin').html(keyword.key)
        $('#xsry_queding').find('.inin').data('id',keyword.id)
        $('#xsry_queding').show()
        $('#xsry_input').hide()
        $('#xsry_queding').find('input').val(keyword.id)
        for(var i = 0;i<xsryName.length;i++){
            if(xsryName[i].id==keyword.id){
                $('[name=ssbm]').val(xsryName[i].ssbm_id)
                $('#ssbm').html(xsryName[i].ssbm)
            }
        }
    });

    //关闭销售人员选择
    $('#xsry_queding .close').click(function () {
        $(this).closest('#xsry_queding').hide().find('.inin').html('')
        $(this).closest('#xsry_queding').hide().find('input').val('')
        $('#xsry_input').show().find('input').val('')
    })

    //弹出核销面单树
    $('#selecthxdmxbh').click(function () {
        top.layer.open({
            type:2,
            area:['60%','60%'],
            maxmin:true,
            content:'{:url("open/hxdbh2",["jxs_id"=>request()->param("jxs_id")])}',
            btn:['确定','关闭'],
            yes:function (i,o) {
                var a = $(o).find('iframe').contents()

                var id =  a.find("#renyuan").val();
                var name =  a.find("#renyuanname").val();
                var hxje = a.find('#hxje').val();
                if(id){
                    var jxs_queding = $('#hxdmxbh_queding')
                    var jxs_input = $('#hxdmxbh_input')

                    jxs_queding.find('.inin').html(name)
                    jxs_queding.find('.inin').data('id',id)
                    jxs_queding.show()
                    jxs_queding.find('input').val(id)
                    jxs_input.hide()
                    $('[name=hxje]').val(hxje)
                    $('#hxje').html(hxje)
                }

                top.layer.close(i)
            }
        })
        return  false
    })
    //核销单编号搜索自动补全
    $("#hxdmxbh").bsSuggest({
        url: '{:url("bs/hexiaosn_bufei",["jxs_id"=>request()->param("jxs_id")])}',
        effectiveFields: ["id", "sn"],
        searchFields: [ "sn"],
        effectiveFieldsAlias: {sn: "核销编号"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "sn",
        clearable: true
    }).on('onDataRequestSuccess', function (e, result) {
        hexiao = result.value
        console.log('onDataRequestSuccess: ', result);
    }).on('onSetSelectValue', function (e, keyword) {
        $('#hxdmxbh_queding').find('.inin').html(keyword.key)
        $('#hxdmxbh_queding').find('.inin').data('id',keyword.id)
        $('#hxdmxbh_queding').show()
        $('#hxdmxbh_input').hide()
        $('#hxdmxbh_queding').find('input').val(keyword.id)
        for(var i = 0;i<hexiao.length;i++){
            if(hexiao[i].id==keyword.id){
                $('[name=hxje]').val(hexiao[i].hxje)
                $('#hxje').html(hexiao[i].hxje)
            }
        }
    }).on('onUnsetSelectValue', function () {
        console.log("onUnsetSelectValue");
    });

    //关闭经销商选择
    $('#hxdmxbh_queding .close').click(function () {
        $(this).closest('#hxdmxbh_queding').hide().find('.inin').html('')
        $(this).closest('#hxdmxbh_queding').hide().find('input').val('')
        $('#hxdmxbh_input').show().find('input').val('')
    })

    function back() {
        history.go(-1)
    }

    var AgencyName = $("#AgencyName");
    sousuo(AgencyName)

    function sousuo(id) {
        id.bsSuggest({
            allowNoKeyword: false, //是否允许无关键字时请求数据
            multiWord: true, //以分隔符号分割的多关键字支持
            separator: ",", //多关键字支持时的分隔符，默认为空格
            getDataMethod: "url", //获取数据的方式，总是从 URL 获取
            url: 'http://unionsug.baidu.com/su?p=3&t=' + (new Date()).getTime() + '&wd=',
            /*优先从url ajax 请求 json 帮助数据，注意最后一个参数为关键字请求参数*/
            jsonp: 'cb',
            /*如果从 url 获取数据，并且需要跨域，则该参数必须设置*/
            processData: function (json) { // url 获取数据时，对数据的处理，作为 getData 的回调函数
                var i, len, data = {
                    value: []
                };
                if (!json || !json.s || json.s.length === 0) {
                    return false;
                }

                // console.log(json);
                len = json.s.length;

                jsonStr = "{'value':[";
                for (i = 0; i < len; i++) {
                    data.value.push({
                        word: json.s[i]
                    });
                }
                data.defaults = 'baidu';

                //字符串转化为 js 对象
                return data;
            }
        });

    }
</script>
</body>

</html>
